class Solution(object):
    def isMatch(self, text, pattern):
        if not pattern:
            return not text

        first_match = bool(text) and pattern[0] in {text[0], '.'}

        if len(pattern) >= 2 and pattern[1] == '*':
            return (self.isMatch(text, pattern[2:]) or
                    first_match and self.isMatch(text[1:], pattern))
        else:
            return first_match and self.isMatch(text[1:], pattern[1:])


s = Solution()
fuck = []
# fuck.append(("aa", "a*"))
# fuck.append(("ab", ".*c"))
# fuck.append(("mississippi", "mis*is*p*."))
# fuck.append(("aab", "c*a*b*"))
fuck.append(("aaaaaaaaaaaaab", "a*a*a*a*a*a*a*a*a*a*c"))
for i in fuck:
    print(s.isMatch(i[0], i[1]))
